$def with (page)

$ lang = page.key.split('.')[-1]
$ namespace = find_i18n_namespace(page.key)

$ _x = ctx.setdefault('bodyid', 'edit')

$var title: $_("Edit %(title)s", title=page.key)


<script type="text/javascript">
function change_ns(ns) {
	document.forms['i18n']['ns'].value = ns;
	document.forms['i18n'].submit();
}

function changelang() {
    var lang = \$("#id_lang").attr('value');
	window.location.href = "/i18n$namespace/strings." + lang + "?m=edit";
}

function add_key() {
	var key = document.getElementById("newkey").value;
	var table = document.getElementById("strings_table");
	var row = table.insertRow(table.rows.length);
	var cell1 = row.insertCell(0);
	var cell2 = row.insertCell(1);
	cell1.innerHTML = key;
        cell2.innerHTML = '<input type="text" name="string_' + key + '" value="" />';
        \$("table#strings_table tr:last td:first").attr("class", "formheader-i18n");
        \$("table#strings_table tr:last td:last").attr("class", "i18n-value");

        \$("#newkey").val("");
        \$("#strings_table input:last").focus();


	return false;
}


window.q.push(function() {
    \$("#newkey").bind("keypress", function(e) {
        if (e.keyCode == 13) {
            \$("#button_addkey").click();
            return false;
        }
    });
});

</script>

<form method="post">

$:render_template("lib/edit_head", page)

<div id="contentBody">

        <div class="formElement title">
            <div class="label">
                <label for="title">$_("Title")</label>
            </div>
            <div class="input">
                <input type="text" name="title" id="title" value="$page.title"/>
            </div>
        </div>

        $:macros.TypeChanger(page.type)

        <div class="clearfix"></div>
        Change language: $:Dropdown('lang', i18n.get_languages(), onchange="changelang();", id="id_lang", value=lang).render()
        <input type="hidden" name="ns" value="$namespace">


    <table width="100%">
        <tr>
            <td style="vertical-align: top; white-space: nowrap;>

            $ xnamespace = namespace or "/"

            $for ns in i18n.get_namespaces():
                $if ns == xnamespace:
                    <span class="red">&rarr;</span>
                    $(ns or "root")
                $else:
                    <a href="/i18n$ns/strings.$lang?m=edit" >$ns</a>
                <span class="smaller">$(i18n.get_count(ns, lang))/$i18n.get_count(ns)</span>
                <br/>

            </td>
            <td style="vertical-align: top" width="100%">
                <table id="strings_table">
                $for key in i18n.getkeys(namespace, lang):
                    <tr>
                        <td class="formheader-i18n">$key</td>
                        <td width="100%" style="padding-left: 20px">
                            <input type="text" name="string_$key" value="$page.get('string_' + key, '')" style="width: 100%" />
                        </td>
                    </tr>
                </table>
                <br /><br />
                <span class="darkgreen">
                    $i18n.get('/type/i18n', 'add_new_key')
                    <input type="text" name="_newkey" id="newkey"/>
                </span>
                <button type="button" id="button_addkey" onclick="add_key()" name="_addkey" value="$i18n.get('/type/i18n', 'add')" class="addkey-small" />Add</button>


            </td>
        </tr>
    </table>

    $:macros.EditButtons(comment=page.comment_)

</div>

</form>
